﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;
using System.Xml;
using System.IO;
using System.Net;
using System.Data.SqlClient;
using System.Xml.Linq;
using System.Data;
using System.Timers;
namespace FB_VB_Contract_Syn
{
    static class Program
    {

        /*[STAThread]
        static void Main()
        {
            Application.EnableVisualStyles();
            Application.SetCompatibleTextRenderingDefault(false);
            Application.Run(new Form1());
        }
        */

        static void Main(string[] args)
        {
            try
            {
                AppDomain currentDomain = AppDomain.CurrentDomain;
                currentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionTrapper);
                Config config = new Config();
                Fishbowl Fishbowl = new Fishbowl();
                DataUtility Utility = new DataUtility();
                String key = "";
                config.start();

                ConnectionObject connectionObject = new ConnectionObject();
                connectionObject = config.ReturnConnection();
                key = config.ReturnKey();
                /*string OrderSql_ContractInvoice = "select distinct order_tbl.order_id,CONVERT(VARCHAR(10),order_item_delivery_date,105) as order_item_delivery_date,order_item_delivery_location,order_item_delivery_invoice_number from order_item_delivery_tbl " +
                                         "left join order_item_tbl on order_item_tbl.order_item_id = order_item_delivery_tbl.order_item_id " +
                                         "left join order_tbl on order_tbl.order_id = order_item_tbl.order_id " +
                                         "where  order_item_delivery_invoice_number > 0 and order_item_delivery_id not in " +
                                         "(select order_item_delivery_id from order_item_delivery_fb_tbl) "+
                                         "and "+
                                         "order_item_delivery_date >= "+
                                         "DATEADD(hh, DATEDIFF(hh,0,dateadd(hh, -1*1, getdate())), 0) "+
                                         "and order_item_delivery_date <= DATEADD(hh, DATEDIFF(hh,0,dateadd(hh, 0, getdate())), 0)";
                */
                string OrderSql_ContractInvoice = "select distinct order_tbl.order_id,order_tbl.order_Status,order_tbl.order_date,order_tbl.order_ContractCompany,order_cc_id, " +
                "CONVERT(VARCHAR(10),order_item_delivery_date,23) as order_item_delivery_date,order_item_delivery_location,order_item_delivery_invoice_number from order_item_delivery_tbl " +
                                         "left join order_item_tbl on order_item_tbl.order_item_id = order_item_delivery_tbl.order_item_id " +
                                         "left join order_tbl on order_tbl.order_id = order_item_tbl.order_id " +
                                         "left join onlineshop_order_cc_tbl on onlineshop_order_cc_tbl.order_id =  order_tbl.order_id " +
                                         "where  order_item_delivery_invoice_number <> 0  " +
                                         "and order_item_delivery_id not in (select order_item_delivery_id from order_item_delivery_fb_tbl) " +
                                         "and order_item_delivery_date > '2012-08-01' and order_item_delivery_invoice_number not in (select invoice_number from invoice_tbl)";
                              

                Utility.SaveSO(OrderSql_ContractInvoice,connectionObject, key);
                //Console.ReadLine();
                //4406256 
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message.ToString());
                DataUtility.sendEmail(e.Message.ToString());
            }
        }
        static void UnhandledExceptionTrapper(object sender, UnhandledExceptionEventArgs e)
        {
            DataUtility.sendEmail(e.ToString());
        }
      
    }
}

